package cn.edu.ctbu.datajpacrud.api;
import cn.edu.ctbu.datajpacrud.domain.Teacher;
import cn.edu.ctbu.datajpacrud.service.TeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("api")
@Slf4j
public class TeacherApiController {

    @Autowired
    private TeacherService teacherService;
    @GetMapping("/teacher/list")
    public List<Teacher> list(){

        return teacherService.findAll();
    }
    /**
     *
      * @param teacher
     * @return
     */
    @PostMapping("/insert")
    public Teacher insert(Teacher teacher){
        Teacher teacher1=teacherService.insert(teacher);
        return teacher1;
    }
    @PutMapping("/update")
    public Teacher update(Teacher teacher){
        Teacher teacher1=teacherService.update(teacher);
        return teacher1;
    }


    @DeleteMapping("/delete")
    public void delete(Teacher teacher){
       teacherService.delete(teacher);
    }


}
